/*******************************************************************************
* Purpose: Combine control variables with outputs and key inputs 
* 
* Dependencies:
*   Inputs: Parenting and Daycare
			 - parenting_inputs.dta
		     - daycare_inputs.dta
			IQ, PPVT, Bayley MDI and PDI
			 - DSC0099.dta, 36-Month Stanford-Binet IQ Scale
			 - DSC0101.dta, 36-Month Peabody Picture Vocabulary Test
			 - DSC0045.dta and DSC0071.dta, 12m and 24m Bayley MDI  
			 - DSC0047.dta and DSC0073.dta, 12m and 24m Bayley Motor Scale
*   Output: ihdp_data_0-3.dta
*
* Notes: -
*******************************************************************************/
set more off
clear all

global storage: env storage

use "$storage/ece_parenting/intermediate_data/controls.dta"

////////////////////////////////////////////////////////////////////////////////
////////////////////////// Add Inputs //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
* parenting
merge 1:1 IHDP using "$storage/ece_parenting/intermediate_data/inputs/parenting_inputs.dta", ///
		  generate(_mergeParenting) 
* daycare
merge 1:1 IHDP using "$storage/ece_parenting/intermediate_data/inputs/daycare_inputs.dta", ///
		  generate(_mergeDaycare) 
drop _mergeParenting _mergeDaycare

////////////////////////////////////////////////////////////////////////////////
////////////////////////// Add outputs /////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
* add iq
merge 1:1 IHDP using "$storage/ece_parenting/raw_data/DSC0099.dta", ///
		  generate(_mergeF57) keepusing(IQCAGE)
* add ppvt
merge 1:1 IHDP using "$storage/ece_parenting/raw_data/DSC0101.dta", generate(_mergeF58)
drop _mergeF57 _mergeF58 
* add Bayley MDI
merge 1:1 IHDP using "$storage/ece_parenting/raw_data/DSC0045.dta", generate(_Bay12)
merge 1:1 IHDP using "$storage/ece_parenting/raw_data/DSC0071.dta", generate(_Bay24)
drop if _Bay12 == 2
drop _Bay12 _Bay24
* add Bayley PDI
merge 1:1 IHDP using "$storage/ece_parenting/raw_data/DSC0047.dta", generate(_Bay12)
merge 1:1 IHDP using "$storage/ece_parenting/raw_data/DSC0073.dta", generate(_Bay24)
drop if _Bay12 == 2
drop _Bay12 _Bay24

// keep primary analysis group
drop if PAG == .

rename *, lower
cd $storage/ece_parenting/
capture mkdir "clean_data/"
save "$storage/ece_parenting/clean_data/ihdp_data_0-3.dta", replace
